package com.wuhan.template.module.find.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.internal.LinkedTreeMap;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.find.bean.ZhengwuBean;
import com.wuhan.template.module.find.webview.WebViewActivity;

import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/13.
 */
public class ZhengwuListAdapter extends MyBaseAdapter<ZhengwuBean.ListBean> {

    private Context mContext;
    private List<ZhengwuBean.ListBean> mList;
    private final DisplayImageOptions options;

    public ZhengwuListAdapter(Context context, List<ZhengwuBean.ListBean> list) {
        super(context, list);
        this.mContext = context;
        this.mList = list;
        options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_meishi_layout;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        return new ZhengwuHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {




        final ZhengwuHolder holder = (ZhengwuHolder) viewHolder;
        LinkedTreeMap<String, String> urls = (LinkedTreeMap<String, String>) mList.get(holder.position).getIndexpic();
        String picUrl = urls.get("host")
                + urls.get("dir")
                + urls.get("filepath")
                + urls.get("filename");

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, WebViewActivity.class);
                intent.putExtra("url", mList.get(holder.position).getContent_url());
                intent.putExtra("title", "政务");
                mContext.startActivity(intent);
            }
        });

        String title = mList.get(holder.position).getTitle();
        String pinlun = mList.get(holder.position).getComment_num();

        holder.tvTitle.setText(title);
        if (!"0".equals(pinlun)){
            holder.tvPinlun.setText("评论:"+pinlun);
        }
        ((BaseApplication) mContext
                .getApplicationContext())
                .getImageLoader()
                .displayImage(picUrl, holder.imageView,options);

    }

    class ZhengwuHolder extends BaseViewHolder {

        @BindView(R.id.ms_title)
        TextView tvTitle;

        @BindView(R.id.ms_tupian)
        ImageView imageView;

        @BindView(R.id.ms_pinglun)
        TextView tvPinlun;
    }
}
